package p2p;

/** Class that contains the information of a file discovered by the FOUND command.
 * @author Bruno
 */
public class SearchFile {

	public SearchFile(String hash, String name, long size) {
		this.hash = hash;
		this.name = name;
		this.size = size;
		sizeHumanReadable = Global.sizeToHumanReadable(size);
	}

	/** Increase the number of peers of this file by 1.
	 */
	public void addPeer() {
		peers++;
	}

	/** Returns the file's hash value.
	 * @return Hash value.
	 */
	public String getHash() {
		return hash;
	}

	/** Returns the file name.
	 * @return File name.
	 */
	public String getName() {
		return name;
	}

	/** Returns the size of the file (in bytes).
	 * @return File size.
	 */
	public long getSize() {
		return size;
	}

	/** Returns the file's size in human-readable format.
	 * @return String containing the size of the file in human-readable format.
	 */
	public String getHumanReadableSize() {
		return sizeHumanReadable;
	}

	/** Returns the number of peers sharing this file.
	 * @return Number of peers.
	 */
	public int getPeers() {
		return peers;
	}

	@Override
	public boolean equals(Object obj) {
		if(obj instanceof SearchFile) { // Compare hash value
			return ((SearchFile)obj).hash.equals(hash);
		}
		else
			return false;
	}

	private String hash = null;
	private String name = null;
	private long size = 0;
	private String sizeHumanReadable = "";
	private int peers = 0;
}
